<?Lassoscript
// Last modified 12/19/11 by ECL, Landmann InterActive

// FUNCTIONALITY
// This file builds the Javascript needed for the slider to work.

// TO DO
// Implement the fields slider_title and slider_URL

// CHANGE NOTES
// 8/7/11
// First implementation.
// 12/19/11
// Expanded admin and added support for both NivoSlider and SudoSlider

// Debugging
// Var('svDebug' = 'Y');

// Used to hold the slider Javascript to output
Var('SliderJS' = string);

// Initialize vars to display file matrix
Var('slider_thumb_array' = array);
Var('ImageCount' = integer);
// Used to hold the image paths
Var('ajaxImages' = string);
// Used to hold the captions
Var('imagestext' = string);
// Used to the slider type
Var('SliderType' = string);

// Get Slider Type - Have to do this separately to determine which JS to create
/* SAMPLE QUERY
/* SELECT ST.Slider_Type
FROM cms_slidergroups AS SG
LEFT JOIN cms_slidertype AS ST
	ON (SG.Slider_TypeID=ST.Slider_SliderTypeID)
WHERE SG.sg_groupid = 24
*/
Var('SQLGetSlidertype' = ('SELECT ST.Slider_Type, ST.Slider_SliderTypeID
FROM '+($svSliderGroupsTable)+' AS SG
LEFT JOIN '+($svSliderTypeTable)+' AS ST
	ON (SG.Slider_TypeID=ST.Slider_SliderTypeID)
WHERE SG.sg_groupid = '+($vSliderGroupID)+' LIMIT 1'));
Inline($IV_Sliders, -SQL=$SQLGetSlidertype);
	Records;
		Var('SliderType' = Field('Slider_Type'));
		// Used later to look up the Config records
		Var('vSlider_SliderTypeID' = Field('Slider_SliderTypeID'));
	/Records;
/Inline;

// Get Slider Records
/* SAMPLE QUERY
/* SELECT ST.Slider_Type, SL.slider_id, SL.slider_title, SL.slider_caption, SL.slider_URL, SL.slider_thumb,
	SG.SG_Name
FROM cms_slidergroups AS SG
LEFT JOIN cms_sg2slider
	USING (sg_groupid)
LEFT JOIN cms_slider AS SL
	USING (slider_id)
LEFT JOIN cms_slidertype AS ST
	ON (SG.Slider_TypeID=ST.Slider_SliderTypeID)
WHERE
	SG.sg_groupid = 24 AND
	SG.active = "Y" AND
	SL.active = "Y"
ORDER BY SL.slider_id */
Var('SQLBuildSlider' = ('/* build_slider - $SQLBuildSlider */
SELECT ST.Slider_Type, SL.slider_id, SL.slider_title, SL.slider_caption, SL.slider_URL, SL.slider_thumb,
	SG.SG_Name
FROM '+($svSliderGroupsTable)+' AS SG
LEFT JOIN '+($svSG2SliderTable)+'
	USING (sg_groupid)
LEFT JOIN '+($svSliderTable)+' AS SL
	USING (slider_id)
LEFT JOIN '+($svSliderTypeTable)+' AS ST
	ON (SG.Slider_TypeID=ST.Slider_SliderTypeID)
WHERE
	SG.sg_groupid = '+($vSliderGroupID)+' AND
	SG.active = "Y" AND
	SL.active = "Y"
ORDER BY SL.slider_id'));
	
	Inline($IV_Sliders, -SQL=$SQLBuildSlider);
		If($svDebug == 'Y');
			$SliderJS += ('<p class="debug">45: Found_Count = '+(Found_Count)+'<br>\n');
			$SliderJS += ('45: Error_CurrentError = '+(Error_CurrentError)+'<br>\n');
			$SliderJS += ('45: SQLBuildSlider = '+($SQLBuildSlider)+'</p>\n');
		/If;

		Records;
			// Not used yet
//			Local('ThisPosition_sliderTitle' = Field('slider_title'));
//			Local('ThisPosition_sliderURL' = Field('slider_URL'));
			Local('ThisPosition_sliderCaption' = Field('slider_caption'));
			Local('ThisPosition_sliderThumb' = Field('slider_thumb'));
	
			$ajaxImages += ('\t\"'+($svSliderImagesPath)+(#ThisPosition_sliderThumb)+'\",\n');

/*			// Not used yet
			If(#ThisPosition_sliderTitle != '');
				$imagestext += ('\t\t\t\t<div class="sliderTitle">'+(#ThisPosition_sliderTitle)+'</div>\n');
			/If;
			If(#ThisPosition_sliderURL != '');
				$imagestext += ('\t\t\t<a href="'+(#ThisPosition_sliderURL)+'" target="_blank">');
			/If;
*/
			If(#ThisPosition_sliderCaption != '');
				$imagestext += ('\t\"'+(#ThisPosition_sliderCaption)+'\",\n');
			/If;

		/Records;

	/Inline;

	// Cleanup
	Protect;
		$ajaxImages->removeTrailing(',\n');
		$ajaxImages += '\n';
		$imagestext->removeTrailing(',\n');
		$imagestext += '\n';
	/Protect;

// Create the JS based upon the SliderType
If($SliderType == 'SudoSlider');
	Include(($svBaseHelpersPath)+('build_sliderJS_sudo.inc'));
Else($SliderType == 'NivoSlider');
	Include(($svBaseHelpersPath)+('build_sliderJS_nivo.inc'));
/If;

$SliderJS += '<!-- END build_sliderJS -->\n';

?>